package com.example.study.scheduler;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Async //使用的话就使用异步支持的线程 不加的话就是用定时任务的线程
@Component
public class FileScheduler {

    @Value("${scheduled}")
    private Boolean scheduled;


    @Scheduled(cron = "0/3 * * * * ?")
    public void scheduler1() {
        if (!scheduled) {
            return;
        }
        System.out.println(Thread.currentThread().getName() + "这是定时任务一。。。。");
    }


    @Scheduled(cron = "0/3 * * * * ?")
    public void scheduler2() {
        if (!scheduled) {
            return;
        }
        System.out.println(Thread.currentThread().getName() + "这是定时任务二。。。。");
    }

    @Scheduled(cron = "0/3 * * * * ?")
    public void scheduler3() {
        if (!scheduled) {
            return;
        }
        System.out.println(Thread.currentThread().getName() + "这是定时任务三。。。。");
    }


    @Scheduled(cron = "0/3 * * * * ?")
    public void scheduler4() {
        if (!scheduled) {
            return;
        }
        System.out.println(Thread.currentThread().getName() + "这是定时任务四。。。。");
    }


    @Scheduled(cron = "0/3 * * * * ?")
    public void scheduler5() {
        if (!scheduled) {
            return;
        }
        System.out.println(Thread.currentThread().getName() + "这是定时任务五。。。。");
    }

}
